package com.leadingsoft.web.file.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.leadingsoft.common.constant.Constant;
import com.leadingsoft.core.pojo.UserInfo;
import com.leadingsoft.web.file.service.FileListService;

@RestController
@RequestMapping(value = "/w/file/", produces = "text/plain;charset=UTF-8")
public class FileController {
	@Autowired
	private FileListService fileListService;

	@RequestMapping("uploadFiles")
	public String uploadFiles(@RequestParam MultipartFile[] files, String parentIndexList, Long thisIndex,
			HttpServletRequest request) {
		UserInfo userInfo = (UserInfo) request.getSession().getAttribute(Constant.SESSION_ID);
		return fileListService.saveFileOnStandAlone1(files, parentIndexList, thisIndex, userInfo.getuId());
	}
	@RequestMapping("getFileList")
	public String getFileList(Long thisIndex, HttpServletRequest request) {
		UserInfo userInfo = (UserInfo) request.getSession().getAttribute(Constant.SESSION_ID);
		Integer userId = userInfo.getuId();
		return fileListService.getFileList(thisIndex, userId);
	}
	@RequestMapping("createFolder")
	public String createFolder(String parentIndexList, Long thisIndex, String folderName, HttpServletRequest request) {
		UserInfo userInfo = (UserInfo) request.getSession().getAttribute(Constant.SESSION_ID);
		Integer userId = userInfo.getuId();
		return fileListService.createFolder(parentIndexList, thisIndex, folderName, userId);
	}
	@RequestMapping("renameFolder")
	public String renameFolder(Long thisIndex, String folderName) {
		return fileListService.renameFile(thisIndex, folderName);
	}
	@RequestMapping("deleteToTrash")
	public String deleteToTrash(Long[] thisIndexs) {
		return fileListService.deleteToTrash(thisIndexs);
	}
}
